use ggez::{Context, GameResult, GameError, graphics, mint::Point2};

pub struct State{
    start_angle: f32,
    a_velocity: f32
}

impl State{
    pub fn new() -> State {
        let start_angle = 0.0;
        let a_velocity = 0.1;
        State{start_angle, a_velocity}
    }
}

impl ggez::event::EventHandler<GameError> for State {
    fn update(&mut self, _ctx: &mut Context) -> GameResult {
        Ok(())
    }
    fn draw(&mut self, ctx: &mut Context) -> GameResult {
        let mut canvas = graphics::Canvas::from_frame(ctx, graphics::Color::WHITE);
        let mut points: Vec<Point2<f32>> = vec![];
        let mut angle = self.start_angle;
        for i in 0..80 {
            let x = (i*10) as f32;
            let y = angle.sin()*100.0 + (angle*2.0).sin()*150.0 + (angle*5.0).sin()*50.0 + 300.0;
            let p = Point2{x, y};
            points.push(p);
            angle += self.a_velocity;

            let circle = graphics::Mesh::new_circle(
                ctx, 
                graphics::DrawMode::stroke(2.0), 
                p, 
                20.0, 
                0.1, 
                graphics::Color::BLACK).unwrap();
            canvas.draw(&circle, graphics::DrawParam::default());

            let circle = graphics::Mesh::new_circle(
                ctx, 
                graphics::DrawMode::fill(), 
                p, 
                20.0, 
                0.1, 
                graphics::Color::new(0.0, 0.0, 0.0, 0.4)).unwrap();
            canvas.draw(&circle, graphics::DrawParam::default()); 
        } 
        self.start_angle += 0.02;     
        
        canvas.finish(ctx)?;
        Ok(())
    }
}